home *** CD-ROM | disk | FTP | other *** search
/ PC World 2007 January / PCWorld_2007-01_cd.bin / v cisle / hotkey / AutoHotkey104504_Install.exe / Extras / Run this to install syntax and clip files for PSPad.ahk < prev    next >
Text File  |  2006-08-29  |  9KB  |  281 lines

  1. ;;; ============================================================================
  2. ;;;   FILENAME: Run this to install syntax and clip files for PSPad.ahk
  3. ;;; ============================================================================
  4. ;;;   Install AutoHotkey syntax highlighting and clip files in PSPad
  5. ;;; ============================================================================
  6.  
  7. ;;;   AUTHOR:  Scott Greenberg  
  8. ;;;   COMPANY: SG Technology
  9. ;;;   VERSION: 1.0.1, 02/05/2005 - 02/08/2005
  10. ;;;   WEBSITE: http://gogogadgetscott.info/
  11. ;;;   Copyright 2005. SG Technology. All rights reserved.
  12. ;;;
  13. ;;; ============================================================================
  14. ;;;   HISTORY:
  15. ;;;    1.0.3
  16. ;;;     - The "remove the [ ] brackets" mode overwrites the DEF file (not append).
  17. ;;;    1.0.2
  18. ;;;     - The INI file is copied to PSPad's Syntax folder, not its Context folder.
  19. ;;;     - Fixed the "remove the [ ] brackets" mode to use backslash as escape char.
  20. ;;;     - Original ini file is backed up prior to being overwritten.
  21. ;;;    1.0.1
  22. ;;;     - Fixed some spelling errors.
  23. ;;;     - Removed ] (typo) from line No 42.
  24. ;;;     - Changed "clip library files" to "clip files".
  25. ;;; ============================================================================
  26. ;;;   DISCLAIMER:
  27. ;;;   Permission to use, copy, modify, and distribute this software 
  28. ;;;   for any purpose and without fee is hereby granted, provided 
  29. ;;;   that the above copyright notice appears in all copies and that 
  30. ;;;   both that copyright notice and this permission notice appear in 
  31. ;;;   all supporting documentation.
  32. ;;;
  33. ;;;   THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED
  34. ;;;   WARRANTY.  ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR
  35. ;;;   PURPOSE AND OF MERCHANTABILITY ARE HEREBY DISCLAIMED.
  36. ;;; ============================================================================
  37.  
  38. ;;; Directives, required by this script (do not change)
  39. #SingleInstance force
  40. #EscapeChar \
  41. SetBatchLines,-1
  42. ScriptTitle = AutoHotkey PSPpad Setup
  43. ;;;  Used to aid in bugging script
  44. ;; debugging on  = 1
  45. ;; debugging off = 0
  46. bDebug = 0
  47. IfNotEqual, bDebug, 1
  48. {
  49.     MsgBox, 4, %ScriptTitle%, This will install file for PSPad to handle AutoHotkey scripts.\nWould you like to continue with the install?
  50.     IfMsgBox, No
  51.         ExitApp
  52. }
  53. ;;; Get PSPad exe path from registry.
  54. RegRead, PSPadExe, HKCU, Software\\PSPad, PSPadExe
  55. ;;; Remove quotes from path
  56. StringReplace, PSPadExe, PSPadExe, ",, A
  57. IfNotEqual, bDebug, 0
  58.     PSPadExe = C:\\Program Files\\PSPad\\PSPad.exe
  59. ;;; Allow user to select from dialog, when unable to locate PSPad
  60. IfNotExist, %PSPadExe%
  61.     FileSelectFile, PSPadExe, 1, %A_ProgramFiles%\\PSPad\\PSPad.exe, Select the PSPad executable., Executable (*.exe)
  62. IfNotExist, %PSPadExe%
  63.     Goto, DownloadPSPad
  64. SplitPath, PSPadExe, PSPadName, PSPadDir
  65.  
  66. ;;; Discover where AutoHotkey and its related files reside.
  67. RegRead, AhkDir, HKLM, SOFTWARE\\AutoHotkey, InstallDir
  68. if (ErrorLevel or not FileExist(AhkDir . "\\AutoHotkey.exe"))  ; Not found, so try best-guess instead.
  69.     SplitPath, A_AhkPath,, AhkDir
  70. AHKExe = %AhkDir%\\AutoHotkey.exe
  71.  
  72. ;;; Allow user to select from dialog, when unable to locate AutoHotkey
  73. IfNotExist, %AHKExe%
  74.     FileSelectFile, AHKExe, 1, %A_ProgramFiles%\\AutoHotkey\\AutoHotkey.exe, Select the AutoHotkey executable., Executable (*.exe)
  75. IfNotExist, %AHKExe%
  76.     Goto, DownloadAHK
  77.  
  78. ;;; Close PSPad
  79. Process, Exist, %PSPadName%
  80. if ErrorLevel <> 0
  81. {
  82.     If bDebug <> 1
  83.         Process, Close, %PSPadName%
  84. }
  85. ;;; Copy files to PSPad dir
  86. file = %A_WORKINGDIR%\\AutoHotkey.def
  87. IfExist, %file%
  88. {
  89.     ;;; Added by beardboy:
  90.     MsgBox, 4, Customize the clip file (.DEF), Would you like to remove the [ ] brackets from optional parameters of commands in the clip file?, 30
  91.     IfMsgBox, Yes
  92.     {
  93.         FileDelete, %PSPadDir%\\Context\\AutoHotkey.def  ; If it exists, overwrite.
  94.         Loop, read, %file%, %PSPadDir%\\Context\\AutoHotkey.def
  95.         {
  96.             IfInString, A_LoopReadLine, [,
  97.             {
  98.                 StringReplace, temp, a_loopreadline, %a_space%[,, All
  99.                 StringReplace, temp, temp, ],, All
  100.                 StringReplace, temp, temp, %a_space%\,, \,, All
  101.                 FileAppend, %temp%\n
  102.             }
  103.             else
  104.                 FileAppend, %A_LoopReadLine%\n
  105.         }
  106.     }
  107.     else
  108.         FileCopy, %file%, %PSPadDir%\\Context\\, 1
  109. }
  110.  
  111. ;;; End
  112.  
  113. file = %A_WORKINGDIR%\\AutoHotkey.ini
  114. IfExist, %file%
  115. {
  116.     ; Make backup of old file if it exists and if there isn't already a backup file (this relies
  117.     ; on it failing to do anything otherwise):
  118.     FileMove, %PSPadDir%\\Syntax\\AutoHotkey.ini, %PSPadDir%\\Syntax\\AutoHotkey (previous).ini
  119.     FileCopy, %file%, %PSPadDir%\\Syntax\\, 1
  120. }
  121. ;;; Get current user highlighter settings from ini
  122. PSPadINI = %PSPadDir%\\PSPad.INI
  123. IniRead, UserHighLighterName1, %PSPadINI%, Config, UserHighLighterName, General
  124. IniRead, UserHighLighterName2, %PSPadINI%, Config, UserHighLighterName1, General
  125. IniRead, UserHighLighterName3, %PSPadINI%, Config, UserHighLighterName2, General
  126. IniRead, UserHighLighterName4, %PSPadINI%, Config, UserHighLighterName3, General
  127. IniRead, UserHighLighterName5, %PSPadINI%, Config, UserHighLighterName4, General
  128. FoundE = 0
  129. FoundP = 0
  130. Loop, 5
  131. {
  132.     value := UserHighLighterName%a_index%
  133.     If value =
  134.     {
  135.         FoundE = %a_index%
  136.         break
  137.     }
  138.     StringGetPos, iPos, value, General
  139.     IfGreaterOrEqual, iPos, 0
  140.     {
  141.         FoundE = %a_index%
  142.         break
  143.     }
  144.     StringGetPos, iPos, value, AutoHotkey
  145.     IfGreaterOrEqual, iPos, 0
  146.     {
  147.         FoundP = %a_index%
  148.         break
  149.     }
  150. }
  151. If FoundP
  152. {
  153.     MsgBox, 4, %ScripT%, PSPad is already setup to handle AutoHotkey scripts.\nWould you like to continue anyways?,
  154.     IfMsgBox, No
  155.         ExitApp, -1  
  156.     FoundE = %FoundP%
  157. }
  158. ;;; Setup AutoHotkey as an user highlighter in ini
  159. If FoundE <> 0
  160. {
  161.     EnvSub, FoundE, 1
  162.     IfLessOrEqual, FoundE, 0
  163.         FoundE = 
  164.     Key = UserHighLighterName%FoundE%
  165.     IniWrite, AutoHotkey, %PSPadINI%, Config, %Key%
  166. }
  167. else
  168. {
  169.     Gosub, SelectUserHighLighter
  170.     EnvSub, FoundE, 1
  171.     IfLessOrEqual, FoundE, 0
  172.         FoundE = 
  173.     Key = UserHighLighterName%FoundE%
  174.     IniWrite, AutoHotkey, %PSPadINI%, Config, %Key%
  175. }
  176. ;;; Added configuration for highlighter to ini
  177. IniWrite, AutoHotkey (*.ahk)|*.ahk, %PSPadINI%, AutoHotkey, Filter
  178. value = %AHKDir%\\AutoHotkey.chm
  179. IniWrite, %value%, %PSPadINI%, AutoHotkey, Compilator Help
  180. value = %AHKDir%\\Compiler\\Ahk2Exe.exe
  181. IniWrite, %value%, %PSPadINI%, AutoHotkey, Compilator File
  182. IniWrite, /in "\%File\%", %PSPadINI%, AutoHotkey, Compilator Param
  183. value = Run,|%AHKDir%\\AutoHotkey.exe| |\%File\%|º
  184. IniWrite, %value%, %PSPadINI%, AutoHotkey, Prog0
  185. value = AU3_Spy,|%AHKDir%\\AU3_Spy.exe|
  186. IniWrite, %value%, %PSPadINI%, AutoHotkey, Prog1
  187. MsgBox, 4, ScriptTitle, Whould you like to setup custom colors w/ light blue background?, 30
  188. IfMsgBox, Yes
  189. {
  190.     IniWrite, 0000800000FFF0DC010, %PSPadINI%, AutoHotkey, Comment
  191.     IniWrite, 1FFFFFFF00FFF0DC000, %PSPadINI%, AutoHotkey, Identifier
  192.     IniWrite, 0080400000FFF0DC100, %PSPadINI%, AutoHotkey, Key
  193.     IniWrite, 000080FF00FFF0DC100, %PSPadINI%, AutoHotkey, Key words 2
  194.     IniWrite, 0000800000FFF0DC100, %PSPadINI%, AutoHotkey, Key words 3
  195.     IniWrite, 000000FF00FFF0DC000, %PSPadINI%, AutoHotkey, Label
  196.     IniWrite, 1FFFFFFF00FFF0DC000, %PSPadINI%, AutoHotkey, Number
  197.     IniWrite, 000000FF00FFF0DC010, %PSPadINI%, AutoHotkey, Preprocessor
  198.     IniWrite, 0000008000FFF0DC100, %PSPadINI%, AutoHotkey, Reserved word
  199.     IniWrite, 0080800000FFF0DC000, %PSPadINI%, AutoHotkey, Space
  200.     IniWrite, 000000FF00FFF0DC000, %PSPadINI%, AutoHotkey, String
  201.     IniWrite, 0000000000FFF0DC000, %PSPadINI%, AutoHotkey, Symbol
  202. }
  203.  
  204. ;;; Open PSPad
  205. If bDebug <> 1
  206.     Run, %PSPadExe%
  207.  
  208. ExitApp
  209.  
  210.  
  211. SelectUserHighLighter:
  212. valSet := 0
  213. Gui, Font, s10 cBlue, Lucida Console
  214. Gui, Add, Text,, Select a User HighLighter to replace:
  215. Gui, Add, Radio, checked vFoundE, &1 %UserHighLighterName1%
  216. Loop, 4
  217. {
  218.     index := a_index + 1
  219.     value := UserHighLighterName%index%
  220.     Gui, Add, Radio,, &%index% %value%
  221. }
  222. Gui, Add, Button, Default, &OK
  223. Gui, Show, AutoSize, ScriptTitle
  224. Loop
  225. {
  226.     if valSet
  227.         break
  228. }
  229. Gui, Submit
  230. Gui, Destroy
  231. Return
  232.  
  233. ButtonOK:
  234. valSet = 1
  235. Return
  236.  
  237. GuiClose:
  238. Gui, Submit
  239. Gui, Destroy
  240. valSet = 1
  241. Return
  242.  
  243. DownloadPSPad:
  244. url = http://www.pspad.com/
  245. valSet := 0
  246. Gui, Font, norm
  247. Gui, Add, Text,, It appears PSPad is not installed. Unable to continue.
  248. Gui, Font, underline 
  249. Gui, Add, Text, cBlue gOpenLink, Click here to Download PSPad.
  250. Gui, Font, norm
  251. Gui, Add, Button, Default, &OK
  252. Gui, Show, AutoSize, ScriptTitle
  253. Loop
  254. {
  255.     if valSet
  256.         break
  257. }
  258. ExitApp -1
  259.  
  260. DownloadAHK:
  261. url = http://www.autohotkey.com/
  262. valSet := 0
  263. Gui, Font, norm
  264. Gui, Add, Text,, We sure AutoHotkey is installed but we are unable to find it. Unable to continue.
  265. Gui, Font, underline
  266. Gui, Add, Text, cBlue gOpenLink, Click here to Download AutoHotkey.
  267. Gui, Font, norm
  268. Gui, Add, Button, Default, &OK
  269. Gui, Show, AutoSize, ScriptTitle
  270. Loop
  271. {
  272.     if valSet
  273.         break
  274. }
  275. ExitApp -1
  276.  
  277. OpenLink: 
  278. Run, %url%
  279. ExitApp -1
  280. return
  281.